package main 

import (
	//"fmt"
	"os"
	"text/template"
)

type Server struct {
	Server string
	Port int
	MaxFails int	//2
	FailTimeout int //3
	Weight int
}
type Upstream struct {
	Name string
	Use_sticky  int
	Use_RR      int
	Use_IP_HASH int
	Servers []Server
}
type Location struct {
	Host string
	Path string
	Upstream Upstream
}

func main() {
	//

	
	location1 := Location{"abc.com","/abc/", Upstream{"xxx", 1,1,0,[]Server{{"127.0.0.1", 2, 3, 80, 20},{"127.0.0.2",2, 3, 81, 10}}}	}
	location2 := Location{"ccc.com","/ccc/", Upstream{"bbb", 0,0,1,[]Server{{"127.0.0.1", 2, 3, 80, 20},{"127.0.0.2",2, 3, 81, 10}}}	}
	locations := []Location{location1, location2}

	tmpl, err := template.ParseFiles("nginx.conf.tmpl")
	if err != nil {
		print("error %s", err.Error())
	}

	err = tmpl.Execute(os.Stdout, locations)
	if err != nil {
		print("error %s", err.Error())
	}

}